<?php
// @formatter:off
/**
 * @file 4.php
 * @author Alejandro Dario Simi
 * @date $Date: 2013-07-07 18:03:56 +0000 (Sun, 07 Jul 2013) $
 *
 * $Id: 4.php 91 2013-07-07 18:03:56Z daemonraco@gmail.com $
 * $URL: http://wcomix.googlecode.com/svn/tags/wcomix-1.0/install/steps/4.php $
 */
// @formatter:on

if(defined("__INSTALLER__")) {
	if(is_readable($wcPaths["config-local"])) {
		@unlink($wcPaths["install-tmps"]["group"]);
		@unlink($wcPaths["install-tmps"]["db"]);
		@unlink($wcPaths["install-tmps"]["defaults"]);

		echo "\t\t\t\t<p>[OK:Local configuration already generated and installed.]</p>\n";
		$isOkToContinue = true;
		$isOkToReload = true;
	} else {
		$tempConf = basename($wcPaths["config-local"]);
		$fullTempConf = "{$wcPaths["cache-directory"]}/$tempConf";

		if(is_readable($fullTempConf)) {
			if(is_writable(dirname($wcPaths["config-local"]))) {
				echo "\t\t\t\t<p>[OK:Local configuration already generated.]</p>\n";
				copy($fullTempConf, $wcPaths["config-local"]);
				unlink($fullTempConf);
				$isOkToContinue = true;
				$isOkToReload = true;
			} else {
				echo "\t\t\t\t<p>[FL:Local configuration already generated, but not moved.]</p>\n";
				echo "\t\t\t\t<p>Please, manually move file '{$fullTempConf}' to '{$wcPaths["config-local"]}' and then reload this page.</p>\n";
				$isOkToContinue = false;
				$isOkToReload = false;
			}
		} else {
			echo "\t\t\t\t<p>This is step {$wciStepCheck}. Here, the instalation process will attempt to generate a local configuration file called '{$tempConf}'\n";
			echo "\t\t\t\tusing information collected from previous steps.</p>\n";

			echo "\t\t\t\t<p><span class=\"Warning\">Please wait while it's generated...</span></p>\n";

			$aux = "<?php\n";
			$aux .= "// @formatter:off\n";
			$aux .= "/*\n";
			$aux .= " * Database Connection Configuration\n";
			$aux .= " */\n";
			$aux .= "\$wcDatabaseAccess[\"server\"]	= \"{$wcDatabaseAccess["server"]}\";\n";
			$aux .= "\$wcDatabaseAccess[\"username\"]	= \"{$wcDatabaseAccess["username"]}\";\n";
			$aux .= "\$wcDatabaseAccess[\"password\"]	= \"{$wcDatabaseAccess["password"]}\";\n";
			$aux .= "\$wcDatabaseAccess[\"database\"]	= \"{$wcDatabaseAccess["database"]}\";\n";
			$aux .= "\$wcDatabaseAccess[\"prefix\"]	= \"{$wcDatabaseAccess["prefix"]}\";\n";
			$aux .= "\n";

			$aux .= "/*\n";
			$aux .= " * Setting Default Group\n";
			$aux .= " */\n";
			$aux .= "\$wcDefaults[\"group\"]		= {$wcDefaults["group"]};\n";
			$aux .= "\n";

			$aux .= "/*\n";
			$aux .= " * Site Values\n";
			$aux .= " * @{\n";
			$aux .= " */\n";
			$aux .= "\$wcSite[\"name\"]		= \"{$wcSite["name"]}\";\n";
			$aux .= "\$wcSite[\"email\"]	= \"{$wcSite["email"]}\";\n";
			$aux .= "\$wcSite[\"wiki\"]		= ".($wcSite["wiki"] ? "\"{$wcSite["wiki"]}\"" : "false").";\t// i.e.: http://mywikihost.com/wiki/\n";
			$aux .= "/* @} */\n";
			$aux .= "\n";

			$aux .= "/*\n";
			$aux .= " * Setting Default Values\n";
			$aux .= " * @{\n";
			$aux .= " */\n";
			$aux .= "\$wcDefaults[\"page-cache\"]	= ".($wcDefaults["page-cache"] ? "true" : "false").";\n";
			$aux .= "\$wcDefaults[\"public-group\"]	= ".($wcDefaults["public-group"] ? "true" : "false").";\n";
			$aux .= "\$wcDefaults[\"session-max-time\"]	= ".($wcDefaults["session-max-time"] !== false ? "\"{$wcDefaults["session-max-time"]}\"" : "false").";\t// in seconds.\n";
			$aux .= "\$wcDefaults[\"stats-max-time\"]	= ".($wcDefaults["stats-max-time"] !== false ? "\"{$wcDefaults["session-max-time"]}\"" : "false").";\t// in days.\n";
			$aux .= "/*\n";
			$aux .= " * \$wcDefaults[\"action\"] can have any of these values:\n";
			$aux .= " *	- WC_ACTION_RANDOM\n";
			$aux .= " *	- WC_ACTION_COLLECTION_LIST\n";
			$aux .= " *	- WC_ACTION_TAG_LIST\n";
			$aux .= " *	- WC_ACTION_DIRECTORY_LIST\n";
			$aux .= " *	- WC_ACTION_NOTHING\n";
			$aux .= " */\n";
			$aux .= "\$wcDefaults[\"action\"]		= {$wcDefaults["action"]};\n";
			$aux .= "/*\n";
			$aux .= " * \$wcDefaults[\"mobile-action\"] can have any of these values:\n";
			$aux .= " *	- WC_ACTION_LOGO\n";
			$aux .= " *	- WC_ACTION_MENU\n";
			$aux .= " *	- WC_ACTION_COLLECTION_LIST\n";
			$aux .= " *	- WC_ACTION_TAG_LIST\n";
			//$aux .= " *	- WC_ACTION_DIRECTORY_LIST\n";
			$aux .= " */\n";
			$aux .= "\$wcDefaults[\"mobile-action\"]	= {$wcDefaults["mobile-action"]};\n";
			$aux .= "/* @} */\n";
			$aux .= "\n";

			$aux .= "/*\n";
			$aux .= " * Installation flag\n";
			$aux .= " * set this variable to true in order to disable install section '{$wcPaths["install-directory"]}'.\n";
			$aux .= " */\n";
			$aux .= "\$wcDefaults[\"installed\"]	= false;\n";
			$aux .= "\$wcDatabase[\"aggressive\"]	= ".($wcDatabase["aggressive"] ? "true" : "false").";\n";
			$aux .= "\n";

			$aux .= "/*\n";
			$aux .= " * Read Only Mode.\n";
			$aux .= " * This flag disables all new data on the system. When true, no new tag,\n";
			$aux .= " * collection, comic or anything will be added to the database\n";
			$aux .= " *\n";
			$aux .= " * Nontheless, basic mechanisms like login/logout, caching and other stuff\n";
			$aux .= " * used to visit the site will be available.\n";
			$aux .= " */\n";
			$aux .= "\$wcDefaults[\"read-only\"]	= false;\n";
			$aux .= "\n";

			$aux .= "/*\n";
			$aux .= " * CMS Credits.\n";
			$aux .= " */\n";
			$aux .= "\$wcDefaults[\"no-credits\"]	= false;\n";
			$aux .= "\n";

			$aux .= "/*\n";
			$aux .= " * This varialbe allos to disable log files.\n";
			$aux .= " */\n";
			$aux .= "\$wcDefaults[\"no-logs\"]	= true;\n";
			$aux .= "\n";

			$aux .= "if(DIRECTORY_SEPARATOR == \"\\\\\") {\n";
			$aux .= "	require_once \"{\$wcROOTDIR}/local.conf.7zip.php\";\n";
			$aux .= "}\n";
			$aux .= "if(is_readable(\"{\$wcROOTDIR}/local.conf.extensions.php\")) {\n";
			$aux .= "	require_once \"{\$wcROOTDIR}/local.conf.extensions.php\";\n";
			$aux .= "}\n";
			$aux .= "\n";

			$aux .= "?>";

			file_put_contents($fullTempConf, $aux);

			$isOkToContinue = false;
			$isOkToReload = true;
		}
	}
}
?>